﻿using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text;


namespace Modulo2
{
    class Program
    {
        static void Main(string[] args)
        {

            var prepositions = new ArrayList { "a", "ante", "bajo", "cabe", "con", "contra", "de", "desde", "durante", "en",
                                                "entre","hacia","hasta","mediante","para","por","según","sin","sobre","tras" };
            var articles = new ArrayList { "el", "la", "lo", "los", "las", "un", "una", "unos", "unas", "al", "del" };
            var connectors = new ArrayList { "abajo","además","arriba","aunque","cierta","cierto","de","delante","derecha","e","encima","entonces",
                                            "es","etc","fin","hasta","igualmente","incluso","izquierda","mas","más","me","ni","o","se","sea","su","pesar",
                                            "pero","porque","que","sino","son","también","u","y" };

            if (args.Count() != 4)
            {
                Console.WriteLine("Args error!");
                return;
            }
            var dataEntreFileName = args[0];
            var dataOutputFileName = args[1];
            var logFileName = args[2];
            var errFileName = args[3];

            int entryRegisterCount = 0;
            int procesedResgisterCount = 0;
            int outputRegisterCount = 0;

            var outputFile = new StreamWriter(dataOutputFileName);
            var logFile = new StreamWriter(logFileName);
            var errFile = new StreamWriter(errFileName);

            logFile.WriteLine("==== Module #2====");
            logFile.WriteLine(DateTime.Now.ToString());
            errFile.WriteLine("==== Module #2====");
            errFile.WriteLine(DateTime.Now.ToString());

            const char Separator = '\n';
            var words = File.ReadAllText(dataEntreFileName, Encoding.UTF8).Split(new[] { Separator });
            foreach (var word in words)
            {
                var correctCord = new String(word.Where(Char.IsLetter).ToArray());

                if (correctCord.Length == 0)
                {
                    continue;
                } 
                entryRegisterCount++;
                if ((!prepositions.Contains(correctCord)) && (!articles.Contains(correctCord)) && (!connectors.Contains(correctCord)))
                {
                    outputFile.WriteLine(correctCord);
                    outputRegisterCount++;
                }
                procesedResgisterCount++;
            }

            logFile.WriteLine("Input Register Count : " + entryRegisterCount);
            logFile.WriteLine("Procesed Register Count : " + procesedResgisterCount);
            logFile.WriteLine("Output Register Count : " + outputRegisterCount);
            logFile.WriteLine(DateTime.Now.ToString());
            errFile.WriteLine(DateTime.Now.ToString());

            outputFile.Flush();
            logFile.Flush();
            errFile.Flush();

            outputFile.Close();
            logFile.Close();
            errFile.Close();
        }
    }
}
